using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using CosyTrade.Data;
using CosyTrade.Organization;

namespace CosyTrade.Distribution
{
    [AddPropertyChangedNotifyInterface, PropertyChangedNotify]
    [ActiveRecord("tbShippingBill"), Serializable]
    public class ShippingBill : BusinessObject
    {
        private readonly Guid primaryKey = Guid.NewGuid();
        private Company onCompany;
        private DateTime beginDatetime = DateTime.Now;
        private DateTime? finishDatetime;
        private Truck truck;
        private Employee driver;
        private IList<OrderBase> billItems = new List<OrderBase>();

        [PrimaryKey(PrimaryKeyType.Assigned, "ROWGUID",
            Access = PropertyAccess.NosetterCamelcase)]
        public override Guid PrimaryKey
        {
            get { return primaryKey; }
        }

        [BelongsTo("companyGuid")]
        public Company OnCompany
        {
            get { return onCompany; }
            set { onCompany = value; }
        }

        [Property]
        public DateTime BeginDatetime
        {
            get { return beginDatetime; }
            set { beginDatetime = value; }
        }

        [Property]
        public DateTime? FinishDatetime
        {
            get { return finishDatetime; }
            set { finishDatetime = value; }
        }

        [BelongsTo("truckGuid")]
        public Truck Truck
        {
            get { return truck; }
            set { truck = value; }
        }

        [BelongsTo("driverGuid")]
        public Employee Driver
        {
            get { return driver; }
            set { driver = value; }
        }

        [HasMany(typeof(OrderBase), ColumnKey="shippingBillGuid",Table="tbShippingBillItems")]
        public IList<OrderBase> BillItems
        {
            get { return billItems; }
            set { billItems = value; }
        }
    }
}